package com.kaifamiao.kfm.controller;

import com.kaifamiao.kfm.service.SysUserService;
import com.kaifamiao.kfm.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private SysUserService sysUserService;

    @RequestMapping
    public ModelAndView index(){
        return new ModelAndView("user.html");
    }

    @GetMapping("/list")
    public JsonResult list(){
        return JsonResult.success(sysUserService.list());
    }

    @RequestMapping("/grant")
    public ModelAndView grant(Long id){
        ModelAndView mv = new ModelAndView("grant.html");
        mv.addObject("id", id);
        return mv;
    }

    @RequestMapping("/grant/list")
    public JsonResult grantList(Long id){
        return JsonResult.success(sysUserService.grantData(id));
    }

    @PostMapping("/grant")
    public JsonResult grantRole(@RequestParam("ids[]") Long[] ids, Long userId){
        return JsonResult.success();
    }

}
